<?php
class it_application_model extends MY_Model {
	var $model = 'it_application';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	* 
					FROM	it_application 
					WHERE	(UPPER(app_id) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(app_name) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(app_desc,'')) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'app_name' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('it_application', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('it_application', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_roleid){
		$result = $this->db->get_where('it_application', array('app_id' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_roleid)
	{
		$result = $this->db->get_where('it_application', array('app_id' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			$this->db->delete('it_application', array('app_id' => $arr_rule['app_id']));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>